Skip to content

@W-18900367 Integration of opentelemetry for SSR Tracing#3133

Merged
jeremy-jung1 merged 142 commits intodevelopfrom
feature/opentelemetry
Aug 28, 2025
Merged

@W-18900367 Integration of opentelemetry for SSR Tracing#3133
jeremy-jung1 merged 142 commits intodevelopfrom
feature/opentelemetry

Conversation

@jeremy-jung1
Copy link
Collaborator

@jeremy-jung1 jeremy-jung1 commented Aug 19, 2025

Description

This feature allows for the tracing of rendering metrics to come up on Monitoring Cloud. When the configurations are set to be enabled, each step of the react rendering process is timed with a span. The spans are connected to a single trace that is visible on Monitoring Cloud after some time.

Merges in this PR + some more commits:

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • (change1) E2E tests for server timing header and x-b3 header
  • (change2) Wrap render with rootSpan creation
  • (change3) For each SSR metric, create an opentelemetry span
  • (change4) Add x-b3 headers creation

How to Test-Drive This PR

On an environment with tracing enabled except SERVER_TIMING

  1. Open a new tab
  2. Open the developer tools and go to Network. Be filtering for "_server"
  3. Go to https://aaa-wasatch-test.mobify-storefront-staging.com/?__server_timing
  4. Click on the network request, and see that you can see the ServerTiming header. Copy the x-b3-traceid
  5. Go to https://monitoring.internal.salesforce.com/argusmvp/#/dashboards/8764299?traceId=null
    -> Note: it may take some time for the traces to show up on monitoring cloud. Metrics get loaded one by one, so sometimes you might see some metrics missing. Search for the traceid again and it will show up
  6. On the top left corner, click Find a Trace by traceid and paste the trace Id and search
  7. See that you can see the durations for these metrics:
ssr.render
ssr.total
ssr.route-matching
ssr.load-component
ssr.fetch-strategies
ssr.fetch-strategies.react-query.pre-render
ssr.fetch-strategies.react-query.use-query.usecategory
ssr.fetch-strategies.react-query.use-query.1
ssr.fetch-strategies.react-query.use-query.useproductsearch
ssr.render-to-string
Screenshot 2025-08-19 at 11 17 05 AM

On an environment with tracing enabled, including SERVER_TIMING

  1. Open a new tab
  2. Open the developer tools and go to Network. Be filtering for "aaa-wasatch"
  3. Go to https://aaa-wasatch-testing.mobify-storefront-staging.com/
  4. Click on the network request, and see that you can see the ServerTiming header. Copy the x-b3-traceid header
  5. Go to https://monitoring.internal.salesforce.com/argusmvp/#/dashboards/8764299?traceId=null
    -> Note: it may take some time for the traces to show up on monitoring cloud. Metrics get loaded one by one, so sometimes you might see some metrics missing. Search for the traceid again and it will show up
  6. On the top left corner, click Find a Trace by traceid and paste the trace Id and search
  7. See that you can see the durations for these metrics:
ssr.render
ssr.total
ssr.route-matching
ssr.load-component
ssr.fetch-strategies
ssr.fetch-strategies.react-query.pre-render
ssr.fetch-strategies.react-query.use-query.usecategory
ssr.fetch-strategies.react-query.use-query.1
ssr.fetch-strategies.react-query.use-query.useproductsearch
ssr.render-to-string
Screenshot 2025-08-19 at 11 17 05 AM

On an environment with tracing disabled

  1. Open a new tab
  2. Open the developer tools and go to Network. be filtering for "test-standard"
  3. Go to https://aaa-wasatch-test-standard.mobify-storefront-staging.com/
  4. Click on the network request, and see that you don't see the ServerTiming header or other headers starting with x-b3

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

larnelleankunda and others added 30 commits June 20, 2025 16:04
…telemetry-server.js

@W-18759755 - Creating tests and a server for open telemetry within the pwa-kit-rea…
…s and metricsas well as creates a test file for it
Signed-off-by: Larnelle Ankunda <lankunda@salesforce.com>
hajinsuha1
hajinsuha1 previously approved these changes Aug 27, 2025
Copy link
Collaborator

@hajinsuha1 hajinsuha1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went through all the tests and reviewed the commits after PR #3028 was merged.
Super cool feature!


export const render = (req, res, next) => {
res.__performanceTimer = new PerformanceTimer({enabled: shouldTrackPerformance(req)})
if (shouldTrackPerformance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing passing req as a parameter?

Suggested change
if (shouldTrackPerformance) {
if (shouldTrackPerformance(req)) {

initializeServerTracing()
}

const tracer = trace.getTracer(getServiceName())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still creating a tracer even when shouldTrackPerformance is false.
See https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3133/files#r2294888717

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks. Added it. Also now tracePerformance is only being called from react-rendering.js if shouldTrackPerformance is true. Otherwise performRender without the tracer creation is called.

adamraya
adamraya previously approved these changes Aug 27, 2025
Copy link
Contributor

@adamraya adamraya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks for all the polishing! I tested by pushing a bundle to cloud production and things LGTM

adamraya
adamraya previously approved these changes Aug 27, 2025
adamraya
adamraya previously approved these changes Aug 27, 2025
@@ -1,181 +1,182 @@
name: SalesforceCommerceCloud/pwa-kit/e2e-pr
Copy link
Collaborator Author

@jeremy-jung1 jeremy-jung1 Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy-jung1 jeremy-jung1 merged commit 59f3c9b into develop Aug 28, 2025
41 checks passed
@jeremy-jung1 jeremy-jung1 deleted the feature/opentelemetry branch August 28, 2025 19:09
@jeremy-jung1 jeremy-jung1 restored the feature/opentelemetry branch September 11, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants